home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 352_01 / vecsum.cpp < prev    next >
C/C++ Source or Header  |  1991-04-22  |  561b  |  27 lines

  1. // vecsum.cpp - sum elements of vector between 2 endpoints 
  2.  
  3. #include <stdlib.h>
  4. #include <alloc.h>
  5. #include <string.h>
  6. #include "wtwg.h"
  7.  
  8. #include "dblib.h"
  9.  
  10. #include "vector.h"
  11.  
  12.  
  13.     float sum (Vector& vec,  int n1, int n2 )
  14.     // sum between point1 and point2 (friend function of Vector)
  15.     // if point2 == -1, sums to end of vec
  16.         {
  17.         float s=0;
  18.  
  19.         if ( n2<0 ) n2 = vec.n;
  20.         float *vv =vec.v;
  21.         for ( int i=n1; i<n2; ++i )
  22.             {
  23.             s+= vv[i];
  24.             }
  25.         return (s);
  26.         }
  27. //----------------------------- end VECSUM.CPP --------------------------